/*
 * Copyright 2012 Alibaba.com All right reserved. This software is the
 * confidential and proprietary information of Alibaba.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Alibaba.com.
 */
package test.fox.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author husong 2012-10-27 下午6:34:30
 */
public class Hello extends HttpServlet {

    int                       number           = 0;
    /**
     * 
     */
    private static final long serialVersionUID = 3147256133642224349L;

    /*
     * (non-Javadoc)
     * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
     */
    @Override
    public void init(ServletConfig config) throws ServletException {
        // TODO Auto-generated method stub
        super.init(config);
    }

    /*
     * (non-Javadoc)
     * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
     * javax.servlet.http.HttpServletResponse)
     */
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter out = resp.getWriter();
        resp.setContentType("text/html;charset=UTF-8");
        resp.setCharacterEncoding("UTF-8");
        out.println("<HTML>");
        out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />");
        out.println("<BODY>");

        out.println("大家好<br/>");
        String numbers = req.getParameter("number");
        double n = 0;
        try {
            n = Double.parseDouble(numbers);
            out.println(Math.sqrt(n));
        } catch (Exception e) {
            out.println("你好");
        }

        // 计数器(变量共享)
        number++;
        out.println("<br/>" + number);
        out.println("</BODY>");
        out.println("</HTML>");
    }
}
